<template>
  <div>
    <van-nav-bar
      :title="comment.reply_count ? comment.reply_count + '条回复' : '暂无回复'"
      @click-left="$emit('close')"
    >
      <template #left>
        <van-icon name="cross" size="18" />
      </template>
    </van-nav-bar>
    <div class="scroll-box">
      <comment-item :comment="comment" />
      <van-cell title="全部回复" />
      <comment-list type="c" :source="comment.com_id + ''" :list="list" />
    </div>

    <div class="post-warp">
      <van-button @click="isShowReplyPostComment = true" round>评论</van-button>
    </div>
    <!-- 评论弹层 -->
    <van-popup v-model="isShowReplyPostComment" position="bottom">
      <comment-post @on-success="onSuccess" :target="comment.com_id" :artId="$route.params.artId" />
    </van-popup>
  </div>
</template>

<script>
import CommentItem from '@/components/CommentItem.vue'
import CommentList from './CommentList'
import CommentPost from './CommentPost'
export default {
  components: { CommentItem, CommentList, CommentPost },
  name: 'reply',
  data () {
    return {
      list: [],
      isShowReplyPostComment: false
    }
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  created () {},

  methods: {
    onSuccess (e) {
      this.list.unshift(e)
      this.isShowReplyPostComment = false
      this.comment.reply_count++
    }
  }
}
</script>

<style scoped lang="less">
.post-warp {
  width: 100%;
  height: 100px;
  position: fixed;
  bottom: 0;
  border-top: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: hotpink;
  .van-button {
    width: 640px;
    height: 80px;
  }
}
.scroll-box {
  position: absolute;
  top: 92px;
  bottom: 100px;
  overflow-y: scroll;
  width: 100%;
}
</style>
